package com.time.workshop.ui;

import net.tsz.afinal.FinalHttp;
import net.tsz.afinal.http.AjaxCallBack;
import net.tsz.afinal.http.AjaxParams;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.time.workshop.API;
import com.time.workshop.App;
import com.time.workshop.BaseConstant;
import com.time.workshop.R;
import com.time.workshop.SuperActivity;
import com.time.workshop.bean.BaseResponse;
import com.time.workshop.bean.TimeHallDetail;
import com.time.workshop.injector.Injector;
import com.time.workshop.injector.V;
import com.time.workshop.utils.NewToast;
import com.time.workshop.utils.PreferenceUtil;
import com.time.workshop.view.CircularImageView;

/**
 * 我的榜单详情
 * 
 * @author fanbaolong
 *
 */
public class MyTaskDetailActivity extends SuperActivity
{

	@V
	Button task_datail_titlebar_left_btn;
	@V
	CircularImageView task_datail_face;
	@V
	TextView task_detail_username, task_detail_time;
	@V
	TextView task_detail_title,task_detail_content,task_detail_content_time,task_detail_content_address;
	@V
	ImageView item_task_datail_image;
	
	private String mTaskId;
	
	private class Response extends BaseResponse<TimeHallDetail>{};
	
	private Response mResponse;
	
	private TimeHallDetail mTimeHallDetail;
	

	@Override
	protected void onCreate(Bundle bundle)
	{
		super.onCreate(bundle);
		setContentView(R.layout.activity_my_task_detail);
		init();
	}

	private void init()
	{
		Injector.getInstance().inject(this);
		
		mTaskId = getIntent().getStringExtra("ID");
		
		getData();

		task_datail_titlebar_left_btn.setOnClickListener(this);

	}

	private void getData() {
		
		FinalHttp fh = new FinalHttp();
		AjaxParams params = new AjaxParams();
		params.put("ID", mTaskId);
		
		fh.post(API.task_detail, params, new AjaxCallBack<Object>() {
			
			@Override
			public void onFailure(Throwable t, int errorNo, String strMsg) {
				super.onFailure(t, errorNo, strMsg);
				App.showLog("strMsg=="+strMsg);
			}
			@Override
			public void onSuccess(Object t) {
				super.onSuccess(t);
				App.showLog("t=="+t.toString());
				
				Gson gson = new Gson();
				mResponse = gson.fromJson(t.toString(), Response.class);
				
				if(mResponse.isSuccess()){
					mTimeHallDetail = mResponse.getResult();
					setData();
				}else {
					NewToast.makeText(getApplicationContext(), mResponse.getMessage());
				}
				
				
				
			}
		
			
		});
		
	}
	/** 塞数据 */
	private void setData() {
		task_detail_username.setText(mTimeHallDetail.getUSERNAME());
		task_detail_time.setText(mTimeHallDetail.getC_TIME());
		task_detail_title.setText(mTimeHallDetail.getTITLE());
		task_detail_content.setText(mTimeHallDetail.getNEED_INFO());
		task_detail_content_time.setText(mTimeHallDetail.getNEED_TIME());
		task_detail_content_address.setText(mTimeHallDetail.getNEED_ADDRESS());
	}

	public void onClick(View v)
	{
		switch (v.getId())
		{
		case R.id.task_datail_titlebar_left_btn:
			back();

			break;

		default:
			break;
		}
	}

}
